package com.ywj.collection.MyHashSet;

import java.util.HashSet;

public class HashSetDemo02 {
    public static void main(String[] args) {
        //创建HashSet集合对象
        HashSet<Student> hs = new HashSet<>();

        Student s1 = new Student("zhangsan",28);
        Student s2 = new Student("lisi",27);
        Student s3 = new Student("wangwu",29);
        Student s4 = new Student("zhaoliu",28);

        Student s5 = new Student("zhangsan",28);

        //把学生添加到集合
        hs.add(s1);
        hs.add(s2);
        hs.add(s3);
        hs.add(s4);
        hs.add(s5);

        //[com.ywj.collection.MyHashSet.Student@2c13da15, com.ywj.collection.MyHashSet.Student@77556fd, com.ywj.collection.MyHashSet.Student@512ddf17, com.ywj.collection.MyHashSet.Student@368239c8, com.ywj.collection.MyHashSet.Student@5c8da962]
        System.out.println(hs);
        //遍历集合(增强for)
        for (Student s : hs) {
            System.out.println(s.getName() + "," + s.getAge());
        }
    }
}
